package com.lanou3g.hw0520.model;

import com.lanou3g.hw0520.pojo.User;
import com.lanou3g.hw0520.util.JDBCUtil;
import com.lanou3g.hw0520.util.MyResultSet;
import com.lanou3g.hw0520.util.MyStatement;

import java.sql.Connection;

public class Login {
    public User login(String username,String password){
        String sql = "select * from users where name= ? and pwd = ?";
        MyStatement statement = JDBCUtil.statement(sql);
        statement.setString(1,username);
        statement.setString(2,password);
        MyResultSet rs = statement.executeQuery();
        User user = null;
        if (rs.next()) {
            String name = rs.getString("name");
            String pwd = rs.getString("pwd");
            user = new User();
            user.setUsername(name);
            user.setPassword(pwd);
        }
        return user;
    }
}
